<?php 
$Item = $this->Gallery;
?>
<?php $this->placeholder('toolBar')->captureStart();?>

<input type="submit"  value="Сохранить" onclick="blockUI('Сохранение');$('#albumSaveForm').submit();" class="button"/>
<input type="submit"  value="Просмотр" onclick="window.location.href=url('gallery/index/view/id/<?= $Item['id'] ?>')" class="button"/>
<input id="btnCancel1" type="button" value="Отмена загрузки" onclick="cancelQueue(window.upload1);" disabled="disabled" class="button" />
<input type="button" value="Отмена" onclick="window.location.href=url('gallery/edit')" class="button" />


<input type="button" value="Удалить" onclick="window.location.href=url('gallery/edit/delete/id/<?= $Item['id'] ?>')" class="button" style="float: right;"/>
<?php $this->placeholder('toolBar')->captureEnd();?>


<link href="<?php echo $this->baseUrl ( "stuff/uploader/css/uploader.css" )?>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo $this->baseUrl ( "stuff/uploader/js/swfupload.js" )?>"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl ( "stuff/uploader/js/swfupload.queue.js" )?>"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl ( "stuff/uploader/js/fileprogress.js" )?>"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl ( "stuff/uploader/js/handlers.js" )?>"></script>

<style>
<!--
.photo_item_field_name
{
	width: 100px;
	float: left;
}
-->
</style> 
<script>
var GID = <? echo $Item['id'] ?>;
//function preLoad() {  alert('preLoad'); }
//function loadFailed() {  alert('loadFailed'); }
//function fileDialogStart() {  alert('fileDialogStart'); }
//function fileQueued() {  alert('fileQueued'); }
//function fileQueueError() {  alert('fileQueueError'); }
//function fileDialogComplete() {  alert('fileDialogComplete'); }
//function uploadStart() {  alert('uploadStart'); }
//function uploadProgress() {  alert('uploadProgress'); }
//function uploadError() {  alert('uploadError'); }
//function uploadSuccess() {  alert('uploadSuccess'); }
function uploadComplete() {  
$("#imagesContainer").load(url('gallery/edit/ajax-get-images/id/' + GID),  null,function() {
	$('.confirm_delete').click(deletephoto);
	init();
});
	}

$(document).ready(
function ()
{
$(":text").css('width', '100%');
init();
	
    var upload1, upload2;
    window.onload = function() {
        window.upload1 = new SWFUpload({

            upload_url: "<?php echo $this->baseUrl ( "gallery/edit/pictureupload" )?>",
            post_params: {"yid" : "<?php echo  $Item['id']?>","format":"normal"},

            // File Upload Settings
            file_size_limit : "102400", // 100MB
            file_types : "*.jpg",
            file_types_description : "JPEG image Files",
            file_upload_limit : 30,
            file_queue_limit : 0,
            
            swfupload_preload_handler : preLoad,
            swfupload_load_failed_handler : loadFailed,
            file_dialog_start_handler : fileDialogStart,
            file_queued_handler : fileQueued,
            file_queue_error_handler : fileQueueError,
            file_dialog_complete_handler : fileDialogComplete,
            upload_start_handler : uploadStart,
            upload_progress_handler : uploadProgress,
            upload_error_handler : uploadError,
            upload_success_handler : uploadSuccess,
            upload_complete_handler : uploadComplete,
            button_image_url : "<?php echo $this->baseUrl ( "stuff/uploader/images/button.png" )?>",
            button_placeholder_id : "spanButtonPlaceholder1",
            button_width: 61,
            button_height: 22,
            flash_url : "<?php echo $this->baseUrl("stuff/uploader/swf/swfupload.swf" )?>",
            flash9_url : "<?php echo $this->baseUrl("stuff/uploader/swf/swfupload_fp9.swf" )?>",
            custom_settings : {
            progressTarget : "fsUploadProgress1",
            cancelButtonId : "btnCancel1"
            },
            debug: false
        });

     };

     $('.confirm_delete').click(deletephoto);
	
}
		);


function deletephoto(){
  //  if (confirm('Удалить фотографию?'))
    {
    	   var Link = $(this).attr('href');
    	   $.get(Link);
    	   $(this).parent().parent().parent().slideUp('fast',function(){
    		   $(this).remove();
        	   });
    	   
    }
    return false;
};

function savePictureData(pid, param, value)
{
	$.post(url('gallery/edit/save-picture-data'), {'pid':pid, 'param' : param, 'value': value});
}


function setPhotoFormat(format)
{
	window.upload1.removePostParam('format');
	window.upload1.addPostParam('format',format);
}

function init()
{
	$(".picture_text").blur(function(){
		savePictureData($(this).attr('pid'), 'Text', $(this).val());
		});

	$(".picture_title").blur(function(){
		savePictureData($(this).attr('pid'), 'Title', $(this).val());
		});

	$(".picture_link").blur(function(){
		savePictureData($(this).attr('pid'), 'Link', $(this).val());
		});
}
</script>

<form action="" method="post" enctype="multipart/form-data" id="albumSaveForm">
<table cellpadding="10">
	<tr>
        <td>
            Название:
        </td>
        <td>
            <input type="text" style="width:400px;background: none;border: none;font-weight: bold;" name="Name"  value="<?php echo $Item['Name'];?>"/>
        </td>	
	</tr>
	
	<!--<tr>
        <td>
            Описание:
        </td>
        <td>
            <textarea id="text" name="description"><?php echo $Item['Description'];?></textarea>
        </td>   
    </tr>-->
      
      <tr>
        <td>
            Фотографии:
        </td>
        <td>
        <div id="imagesContainer">
        
        <?php 
            foreach($Item['pictures'] as $Pict)
            {
         ?>
<!--        <div style="width: 100px;height: 100px;float: left;margin: 10px;">-->
<!--        <div  style="float: left;padding: 5px;border: 1px solid #eee;margin: 10px;">-->
<!--        <img  src="<?php echo $this->baseUrl("images/thumb_small/" . $Pict['filename'])  ?>"/>-->
<!--        <div><a class="confirm_delete" href="<?php echo $this->baseUrl('gallery/edit/picturedelete/id/' . $Pict['id'] . '/yid/' . $Item['id'])?>">Удалить</a></div>-->
<!--        </div>-->
<!--        </div>-->

<div style="width: 900px;height: 100px;float: left;margin: 10px;">
        <div  style="float: left;padding: 5px;border: 1px solid #eee;margin: 10px;">
        <div style="float: left;">
        <img style="float: left;padding: 4px;" src="<?php echo $this->baseUrl("images/thumb_small/" . $Pict['filename'])  ?>"/>
        </div>
        
        <div style="float: left;">
        <div style="float: left;"><div class="photo_item_field_name">Заголовок:</div><input style="width: 200px;  color: #777; border: 1px solid #e0e0e0;margin-top: 4px;" type="text" value="<?php echo $Pict['Title']?>"  pid="<?php echo $Pict['id']?>"  class="picture_title"/></div><br />
        <div style="float: left;"><div class="photo_item_field_name">Описание: </div><input style="width: 200px; color:#777; border: 1px solid #e0e0e0;margin-top: 4px;" type="text" value="<?php echo $Pict['Text']?>" pid="<?php echo $Pict['id']?>" class="picture_text" /></div><br />
        <div style="float: left;"><div class="photo_item_field_name">Ссылка:   </div><input style="width: 200px; color:#777; border: 1px solid #e0e0e0;margin-top: 4px;margin-bottom: 10px;" type="text" value="<?php echo $Pict['Link']?>" pid="<?php echo $Pict['id']?>" class="picture_link" /></div><br />
        </div>
        
        <div>&nbsp;&nbsp;<a class="confirm_delete" href="<?php echo $this->baseUrl('gallery/edit/picturedelete/id/' . $Pict['id'] . '/yid/' . $Item['id'])?>">Удалить</a></div>
        </div>
        </div>
        <div style="clear: both;"></div>
        
        <?php }
            ?>
            <div style="clear: both;"></div>
</div>    
            
        </td>   
    </tr><!-- 
        
   <tr>
        <td>
            Размеры:
        </td>
        <td>
             
             <select onchange="setPhotoFormat($(this).val())">
             <option value="normal">Нормальный</option>
             <option value="wide">Широкий</option>
             </select>
        </td>   
    </tr>
        
    --><tr>
        <td colspan="2">
        <div style="padding-top: 30px;">
        <div class="fieldset flash" id="fsUploadProgress1">
                            <span class="legend">Загрузка фотографий</span>
                        </div>
                        <div style="padding-left: 5px;">
        <span id="spanButtonPlaceholder1"></span>
        <div id="btnCancel1"></div>
        
        <br />
        </div>
        </div>
        </td>   
    </tr>  
    
    <tr>
        <td colspan="2">
         &nbsp;
        </td>
    </tr>    

</table>
</form>

<script>
function CheckPurpose()
{
  	if ($('#ppckbox').is(':checked'))
    {
    	$(".purpose").fadeIn();
    }
    else
    {
    	$(".purpose").fadeOut();
    }
}
$(document).ready(CheckPurpose);
$(document).ready(uploadComplete);
</script>
